package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.ProjectChangeReviewRequest;
import com.smart.model.request.ProjectRequest;
import com.smart.model.vo.ProjectChangeReviewVO;
import com.smart.service.ProjectService;
import com.smart.service.SuperviseProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author: zyh
 * @date: 2023-06-20
 */
@RestController
@RequestMapping("/superviseProject")
@Api(value = "监管项目模块", tags = {"云监管平台#项目模块"})
public class SuperviseProjectController {
    @Autowired
    private ProjectService projectService;
    @Autowired
    private SuperviseProjectService superviseProjectService;

    @WebAccess(login = true)
    @ApiOperation("项目编辑")
    @PostMapping("/projectUpdate")
    public WebResponse<String> projectUpdateByKey(@Valid @RequestBody ProjectRequest request, HttpServletRequest req) {
        return WebResponse.build(projectService.projectUpdateByKey(request, req));
    }

    @WebAccess(login = true)
    @ApiOperation("项目审核详情查询")
    @PostMapping("/selectNewProject")
    public WebResponse selectNewProject(@RequestParam(value = "id") Long id) {
        return WebResponse.build(superviseProjectService.selectNewProject(id));
    }

    @WebAccess(login = true)
    @ApiOperation("新项目审核")
    @PostMapping("/newProjectExamine")
    public WebResponse<String> newProjectExamine(@Valid @RequestBody ProjectRequest request, HttpServletRequest req) {
        return WebResponse.build(superviseProjectService.newProjectExamine(request, req));
    }

    @WebAccess(login = true)
    @ApiOperation("查询项目编辑审核内容")
    @PostMapping("/selectProjectChange/{id}")
    public WebResponse<ProjectChangeReviewVO> selectProjectChange(@PathVariable("id") long id) {
        return WebResponse.build(superviseProjectService.selectProjectChange(id));
    }

    @WebAccess(login = true)
    @ApiOperation("项目编辑审核")
    @PostMapping("/oldProjectExamine")
    public WebResponse<String> oldProjectExamine(@Valid @RequestBody ProjectChangeReviewRequest request, HttpServletRequest req) {
        return WebResponse.build(superviseProjectService.oldProjectExamine(request, req));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管、运营管理项目管理列表查询")
    @PostMapping("/selectAllPassProject")
    public WebResponse selectAllPassProject(Pageable pageable,@RequestBody ProjectRequest request) {
        return WebResponse.build(superviseProjectService.selectAllPassProject(request, pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("项目信息审核列表查询")
    @PostMapping("/selectAllExamineProject")
    public WebResponse selectAllExamineProject(@SortDefault(sort = "update_time", direction = Sort.Direction.ASC) Pageable pageable,
                                               @RequestBody ProjectRequest request) {
        return WebResponse.build(superviseProjectService.selectAllExamineProject(request, pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("项目逻辑删除")
    @GetMapping("/delete/{id}")
    public WebResponse delete(@PathVariable("id") Long id) {
        return WebResponse.build(superviseProjectService.delete(id));
    }

    @WebAccess(login = true)
    @ApiOperation("项目审核待办事项提醒")
    @GetMapping("/selectWaitToBeDone")
    public WebResponse<Integer> selectWaitToBeDone() {
        return WebResponse.build(superviseProjectService.selectWaitToBeDone());
    }
}
